package ModelLayer;
import java.util.ArrayList;

/**
 * Write a description of class Order here.
 * 
 * @author (Alexander) 
 * @version (28052013)
 */
public class Order
{
    // instance variables - replace the example below with your own
    private Customer customer;
    private ArrayList<PartOrder> partOrders;
    private int status;

    /**
     * Constructor for objects of class Order
     */
    public Order()
    {
        // initialise instance variables
        this.customer = null;
        partOrders = new ArrayList<PartOrder>();
        this.status = 0;
    }

    
    /**
     * Adds the value of the Customer c to the field customer.
     * 
     * @param c     the id of a Customer object.
     */
    public void addCustomer(Customer c)
    {
        customer = c;    
    }
    
    /**
     * Creates a new PartOrder and adds it to the ArrayList partOrders.
     * 
     * @param i         the id of a Item object.
     * @param quantity  the quantity of the decired item.
     */
    public PartOrder addPartOrder(Item i, int quantity)
    {
        PartOrder p = new PartOrder(i, quantity);
        partOrders.add(p);
        return p;
    }
    
    /**
     * Changes the field status with a status input.
     * 
     * @param status    the id of a status.
     */
    public void changeStatus(int status)
    {
        this.status = status;
    }
    
    public double calculatePrice() {
    	double value = 0;
    	if(partOrders != null) {
    		for(PartOrder po : partOrders) {
    			value += po.getQuantity() * po.getItem().getSalesPrice();
    		}
    	}
    	return value;
    }
}
